package com.dzm.cart.interceptor;

import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 作者：Dzm
 * 时间：2024-09-18-14:54
 * 功能：
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        String name = (String) session.getAttribute("name");
        if(StringUtils.isEmpty(name)) {
            //名称为空说明未登录，去登录
            response.sendRedirect("http://thirdpart.daxigua.com/login?redirectUrl=http://cart.daxigua.com");
            return false;
        }

        return true;
    }
}
